<template>
  <div id="demo">
    <ul class="list">
      <li
        v-for="(item, index) in ulList"
        :key="item.id"
        :class="!index && play ? 'toUp' : ''"
        @click="goInfo(item)"
      >
        {{ item.name }}
      </li>
    </ul>
  </div>
</template>
 
<script>
export default {
  props: {
    ulList: Object
  },
  mounted() {
    setInterval(this.startPlay, 3000)
  },
  data() {
    return {
      play: false
    }
  },
  methods: {
    startPlay() {
      let that = this
      that.play = true //开始播放
      setTimeout(() => {
        that.ulList.push(that.ulList[0]) //将第一条数据塞到最后一个
        that.ulList.shift() //删除第一条数据
        that.play = false //暂停播放,此处修改，保证每一次都会有动画显示
      }, 500)
    },
    goInfo(item){
      this.$emit('goInfo',item)
    }
  }
}
</script>
 
<style lang="less" scoped>
.toUp {
  margin-top: -40px;
  transition: all 0.5s;
}
 
.list {
  list-style: none;
  width: 200px;
  text-align: center;
  overflow: hidden;
  height: 40px;
  padding: 0;
  margin: 0;
}
li {
  text-align: left;
  height: 40px;
  line-height: 40px;
}
</style>
 
 